home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Atari Mega Archive 1
/
Atari Mega Archive - Volume 1.iso
/
gnu
/
gawk
/
cawf2st.zoo
/
pass3.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-04-12
|
21KB
|
579 lines
/*
* pass3.c - cawf(1) pass 3 function
*/
/*
* Copyright (c) 1991 Purdue University Research Foundation,
* West Lafayette, Indiana 47907. All rights reserved.
*
* Written by Victor A. Abell <abe@mace.cc.purdue.edu>, Purdue
* University Computing Center. Not derived from licensed software;
* derived from awf(1) by Henry Spencer of the University of Toronto.
*
* Permission is granted to anyone to use this software for any
* purpose on any computer system, and to alter it and redistribute
* it freely, subject to the following restrictions:
*
* 1. The author is not responsible for any consequences of use of
* this software, even if they arise from flaws in it.
*
* 2. The origin of this software must not be misrepresented, either
* by explicit claim or by omission. Credits must appear in the
* documentation.
*
* 3. Altered versions must be plainly marked as such, and must not
* be misrepresented as being the original software. Credits must
* appear in the documentation.
*
* 4. This notice may not be removed or altered.
*/
#include "cawf.h"
void
Pass3(len, word, sarg, narg)
int len; /* length (negative is special) */
char *word; /* word */
char *sarg; /* string argument */
int narg; /* numeric argument */
{
int addto; /* spaces to add to all words */
int i, j, k; /* temporary index */
char msg[MAXLINE]; /* message buffer */
int n; /* temporary number */
char *s1; /* temporary string pointer */
int wl; /* real word length */
int xsp; /* extra spaces to add */
int vsp; /* vertical spacing status */
vsp = 0;
if (word != NULL)
wl = strlen(word);
/*
* If not a special command, process a word.
*/
if (len >= 0 && Outll < 0) {
/*
* Enter first word.
*/
(void) strcpy(Outln, word);
Outll = len;
Outlx = wl;
Padx = 0;
} else if (len >= 0
&& (Outll+Contlen+len+narg) <= (LL-Pgoff-Ind-Tind)) {
/*
* The word fits, so enter it.
*/
if ((Contlen + len) > 0) {
line_too_big:
if ((Outlx + Contlen + wl) >= MAXOLL) {
Error3(len, word, sarg, narg,
"output line too big");
return;
} else {
if (Contlen > 0 && Cont != NULL) {
if (Contlen == 1 && *Cont == ' ') {
Padchar[Padx++] = Outlx;
Outln[Outlx++] = ' ';
} else {
(void) strcpy(&Outln[Outlx],
Cont);
Outlx += Contlen;
}
}
if (len > 0) {
(void) strcpy(&Outln[Outlx], word);
Outlx += wl;
}
}
}
Outll += Contlen + len;
} else if (len == NOBREAK || len == MESSAGE) {
/*
* Do nothing (equivalent to break)
*/
} else if (len == DOBREAK && strcmp(word, "need") == 0
&& (Nxtln + narg) < (Pglen + 1 - Botmarg)) {
/*
* Do nothing, because there is room on the page.
*/
} else if (len == DOBREAK && strcmp(word, "toindent") == 0
&& (Ind + Tind + Outll) < Ind) {
/*
* Move to indent position with line - there is room.
*/
n = Ind - (Ind + Tind +Outll);
Outll += n;
if ((Outlx + n) >= MAXOLL)
goto line_too_big;
for (i = n; i; i--)
Outln[Outlx++] = ' ';
Padx = 0;
Free(&Cont);
Contlen = 0;
} else if (Outll >= 0
|| (len == DOBREAK && strcmp(word, "need") == 0)) {
/*
* A non-empty line or a "need" forces output.
*/
vsp = 0;
print_line:
if (Nxtln == 1) {
/*
* We're at the top of the page, so issue the header.
*/
if (Thispg > 1)
Charput('\f');
for (i = (Topmarg - 1)/2; i > 0; i--) {
Charput('\n');
Nxtln++;
}
/*
* Print the page header, as required.
*/
if (Fph || Thispg > 1) {
i = LenprtHF(Hdc, Thispg, 0)
+ LenprtHF(Hdl, Thispg, 0)
+ LenprtHF(Hdr, Thispg, 0) + 2;
j = (LL - i - Pgoff) / 2 + 1;
n = LL - Pgoff - i - j + 2;
for (k = 0; k < Pgoff; k++)
Charput(' ');
if (Hdl)
LenprtHF(Hdl, Thispg, 1);
while (j--)
Charput(' ');
if (Hdc)
LenprtHF(Hdc, Thispg, 1);
while (n--)
Charput(' ');
if (Hdr)
LenprtHF(Hdr, Thispg, 1);
Charput('\n');
} else
Charput('\n');
Nxtln++;
while(Nxtln <= Topmarg) {
Charput('\n');
Nxtln++;
}
}
/*
* Add a trailing hyphen, if mecessary.
*/
if (vsp == 0 && Eollen > 0 && Eol != NULL) {
i = strlen(Eol);
if ((Outlx + i) >= MAXOLL)
goto line_too_big;
(void) strcpy(&Outln[Outlx], Eol);
Outlx += i;
Outll += Eollen;
}
/*
* Trim trailing spaces from the output line.
*/
while (Outlx > 0) {
if (Outln[Outlx - 1] != ' ')
break;
if (Padx > 0 && (Outlx - 1) == Padchar[Padx - 1])
Padx--;
Outlx--;
Outln[Outlx] = '\0';
Outll--;
}
if (Outlx == 0)
Charput('\n');
else if (len == DOBREAK && strcmp(word, "center") == 0) {
/*
* Center the output line.
*/
i = (LL - Pgoff - Outll) / 2;
if (i < 0)
i = 0;
for (j = (Pgoff + Ind + Tind + i); j; j--)
Charput(' ');
Stringput(Outln);
Charput('\n');
} else if